#include "init_uart.h"

const uart_port_t uart1_port = UART_NUM_1;
const int uart1_buffer = 1024;
static const int uart1_rate = 57600;

void uart_init(void)
{
    uart_config_t uart_config = {
        .baud_rate = uart1_rate,
        .data_bits = UART_DATA_8_BITS,         // 位数
        .parity = UART_PARITY_DISABLE,         // 校验模式
        .stop_bits = UART_STOP_BITS_1,         // 结束位
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, // cts和rts硬件模拟模式
        // .rx_flow_ctrl_thresh = 122,//如果flow_ctrl设置开启，就设置
        .source_clk = UART_SCLK_DEFAULT, // 时钟设置，默认即可
    };
    ESP_ERROR_CHECK(uart_param_config(uart1_port, &uart_config));
    ESP_ERROR_CHECK(uart_set_pin(uart1_port, uart_tx_num, uart_rx_num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
    ESP_ERROR_CHECK(uart_driver_install(uart1_port, uart1_buffer * 2, 0, 0, NULL, 0));
}
